package com.prig.base.repository;

import com.prig.base.entity.RolePermissionRelation;
import com.prig.base.entity.RolePermissionRelationId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface RolePermissionRelationRepository extends JpaRepository<RolePermissionRelation, RolePermissionRelationId> {

    @Query(nativeQuery = true,value = "SELECT\n" +
            "\tpermission_id,\n" +
            "\trole_id\n" +
            "FROM\n" +
            "\trole_permission_relation\n" +
            "WHERE\n" +
            "\trole_permission_relation.role_id = :roldId")
    List<RolePermissionRelationId> findByRoldId(long roldId);
    @Transactional
    @Query(nativeQuery = true,value = "delete from role_permission_relation where role_id = :roleId")
    @Modifying
    void delete(long roleId);
}
